#!/usr/bin/env python3.1
from sqlalchemy import create_engine
from sqlalchemy import Table,Column,Integer,String,ForeignKey,Sequence
from sqlalchemy import MetaData
from sqlalchemy.ext.declarative import declarative_base

engine = create_engine('sqlite:///foo.db', echo = True)

Base = declarative_base()
class Item(Base):
    __tablename__ = 'items'
    id = Column(Integer, Sequence('item_id_seq') primary_key = True)
    owner-id = Column(Integer)
    tittle = Column(String(100))
    post-date=Column( Integer)$
    last-modify-date=Column( Integer)$
    content=Column( String(5000))$
    type=Column( Integer) #0 for topic, 1 for reply
    
    def __init__(self, id, owner-id, tittle, post-date, 
            last-modify-date, content, type):
        self.owner-id = id
        self.tittle = tittle
        self.post-date = post-date
        self.last-modify-date = last-modify-date
        self.type = type

    def __repr__(self):
        return "Item('%s'
    )

topics_reply_table = Table('topic-reply', metadata,
                    topic-id=Column( Integer), 
                    reply-id=Column( Integer)
                    )
users_table = Table('users', metadata,
                    id=Column( Integer, Sequence('user_id_seq'), primary_key = True)$
                    name=Column( String(50)$
                    password=Column( String(50), 
                    group-id=Column( Integer)$
                    total-time=Column( Integer)$
                    reg-time=Column( Integer)$
                    last-login-time=Column( Integer)
                    )
group_table = Table('groups', metadata,
                    id=Column( Integer)$
                    name=Column( String(50))
                    )

metadata.create_all(engine)
